/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package skyproc;

import java.util.Objects;
import skyproc.SubStringPointer.Files;

/**
 *
 * @author Justin Swanson
 */
public abstract class MajorRecordDescription extends MajorRecordNamed {

    SubStringPointer description = new SubStringPointer(Type.DESC, Files.DLSTRINGS);

    MajorRecordDescription() {
        super();
        description.forceExport = true;
        subRecords.add(description);
    }

    MajorRecordDescription(Mod mod, String edid) {
        super(mod, edid);
        description.forceExport = true;
        subRecords.add(description);
    }

    /**
     *
     * @return Description associated with the Major Record, or <NO TEXT> if
     * empty.
     */
    public String getDescription() {
        return description.print();
    }

    /**
     *
     * @param description String to set as the Major Record description.
     */
    public void setDescription(String description) {
        this.description.setText(description);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final MajorRecordDescription other = (MajorRecordDescription) obj;
        if (!Objects.equals(this.description, other.description)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 79 * hash + Objects.hashCode(this.description);
        return hash;
    }

    /**
     * Merges Major Records with descriptions. Implements MajorRecordNamed's
     * merger.
     *
     * @param no The new MajorRecordDescription to be merged.
     * @param bo The base MajorRecordDescription, to prevent base data from
     * being re-merged.
     * @return The modified MajorRecordDescription.
     */
    @Override
    public MajorRecord merge(MajorRecord no, MajorRecord bo) {
        super.merge(no, bo);
        MajorRecordDescription m = this;
        if (!(no == null && bo == null && (no instanceof MajorRecordDescription) && (bo instanceof MajorRecordDescription))) {
            final MajorRecordDescription nm = (MajorRecordDescription) no;
            final MajorRecordDescription bm = (MajorRecordDescription) bo;
            if (SkyBash.mTags.names) {
                m.description.merge(nm.description, bm.description);
            }
        }
        return m;
    }
}
